package com.example.application1.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.application1.Adapter.newsTabViewPagerAdapter;
import com.example.application1.R;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;


public class news_Fragments extends Fragment {
    private TabLayout tabLayout3;
    private ViewPager viewpager3;
    private List<Fragment> fragments;
    private View view;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.news_fragments, container, false);
        initView();
        initToolbar();
        return view;
    }

    private void initToolbar() {
        Toolbar toolbar =view.findViewById(R.id.my_toolbar);
        toolbar.setTitle("");
        TextView toolbar_title =view.findViewById(R.id.toolbar_title);
        toolbar_title.setText("新闻中心");
//        setSupportActionBar(toolbar);
//        ActionBar actionBar = getSupportActionBar();
//        if (actionBar != null) {
//            actionBar.setDisplayHomeAsUpEnabled(true);
//            actionBar.setHomeAsUpIndicator(R.drawable.icon_back);
//        }
    }

    private void initView() {
        fragments=new ArrayList<>();
        tabLayout3=view.findViewById(R.id.tabLayout3);
        viewpager3=view.findViewById(R.id.viewpager3);

        fragments.add(newsFragment.newInstance());
        fragments.add(GouNeiNewsFragment.newInstance());
        fragments.add(financeNewsFragment.newInstance());
        fragments.add(GouJiNewsFragment.newInstance());
        fragments.add(YuLeNewsFragment.newInstance());
        fragments.add(militaryNewsFragment.newInstance());
        fragments.add(footballNewsFragment.newInstance());


        String[] titles={"头条","国内新闻","财经新闻","国际新闻","娱乐新闻","军事新闻","足球新闻"};
        viewpager3.setAdapter(new newsTabViewPagerAdapter(getChildFragmentManager(),fragments,titles));
        tabLayout3.setupWithViewPager(viewpager3);

    }

}
